<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  
</body>
</html>
<script>
    const dataA = [
      { id: "1", name: "小张" },
      { id: "2", name: "小宋" },
      { id: "3", name: "小孙" },
      { id: "4", name: "小李" },
      { id: "5", name: "小王" },
    ];

    const dataB = [
      { id: "3", name: "小孙" },
      { id: "8", name: "小刘" },
    ];

    // 交集
    const common = [];
    dataB.forEach(itemB=>{
      dataA.forEach(itemA=>{
        if(itemA.id===itemB.id){
          common.push(itemA);
        }
      })
    })
    console.log(common);


    //差集
    const arr = [...dataA,...dataB];
    common.forEach(item=>{
      const diff = arr.filter(data=>{
        return data.id!=item.id;
      })
      console.log(diff);
    })
    
    
</script>